package com.example.blog.service;

import com.example.blog.mapper.BlogMapper;
import com.example.blog.model.BlogInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-05
 * Time: 13:09
 */
@Service
@Slf4j
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> getBlogList() {
        return blogMapper.selectAll();
    }

    public BlogInfo getBlogDetail(Integer id) {
        return blogMapper.selectById(id);
    }

    public Boolean insertBook(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.insertBlog(blogInfo);
            if(result == 1){
                return true;
            }
        }catch (Exception e){
            log.error("添加文章失败，e",e);
        }
        return false;
    }

    public Boolean delete(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.updateBlog(blogInfo);
            if(result == 1){
                return true;
            }
        }catch (Exception e){
            log.error("删除文章失败，e",e);
        }
        return false;
    }

    public Boolean update(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.updateBlog(blogInfo);
            if(result == 1){
                return true;
            }
        }catch (Exception e){
            log.error("删除文章失败，e",e);
        }
        return false;
    }
}
